package group.sicher.common.constant.senum;

import lombok.Getter;

import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;

/**
 * 优惠券的状态
 */
@Getter
public enum CouponStatusEnum {
    CLOSED(0, "关闭"),
    USING(1, "开启");

    private int code;
    private String desc;

    private static final Map<Integer, CouponStatusEnum> lookupInt = new HashMap<>();
    private static final Map<String, CouponStatusEnum> lookupString = new HashMap<>();

    static {
        for (CouponStatusEnum type : EnumSet.allOf(CouponStatusEnum.class)) {
            lookupInt.put(type.getCode(), type);
            lookupString.put(type.getDesc(), type);
        }
    }


    CouponStatusEnum(int code, String desc) {
        this.code = code;
        this.desc = desc;
    }


    public static CouponStatusEnum find(Integer code) {
        return lookupInt.get(code);
    }

    public static CouponStatusEnum find(String desc) {
        return lookupString.get(desc);
    }
}
